#include <iostream>
#include <map>

#define x first
#define y second

using namespace std;

map<string, int> si;
map<int, string> is;

int main()
{
	int T;
	cin >> T;
	
	int cnt = 0;
	
	while (T -- )
	{
		string op;
		cin >> op;
		
		if (op == "touch")
		{
			string s;
			cin >> s;
			
			if (si.count(s)) continue;
			else 
			{
				is[ ++ cnt] = s;
				si[s] = cnt;
			}
		}
		else if (op == "rename")
		{
			string s1, s2;
			cin >> s1 >> s2;
			
			if (!si.count(s1)) continue;
			if (si.count(s2)) continue;
			
			int t = si[s1];
//			is.erase(t);
			si.erase(s1);
			si[s2] = t;
			is[t] = s2;
		}
		else if (op == "rm")
		{
			string s;
			cin >> s;
			
			if (!si.count(s)) continue;
			
			int t = si[s];
			si.erase(s);
			is.erase(t);
		}
		else 
		{
			for(auto p : is)
			{
				cout << p.y << endl;
			}
		}
	}
	
	return 0;
}